package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductService;
import com.atguigu.spzx.model.dto.product.ProductDto;
import com.atguigu.spzx.model.dto.product.ProductSaveDto;
import com.atguigu.spzx.model.result.Result;
import com.atguigu.spzx.model.vo.product.ProductVo;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/product/product")
@Tag(name = "商品管理模块")
public class ProductController {
    @Resource
    ProductService productService;
    @Operation(summary = "商品审批接口")
    @GetMapping("updateAuditStatus/{id}/{auditStatus}")
    public Result updateAuditStatus(@PathVariable("id")Long id,
                                    @PathVariable("auditStatus")Integer auditStatus ){
        productService.updateAuditStatus(id , auditStatus);
        return Result.ok();
    }
    @Operation(summary = "商品上下架接口")
    @GetMapping("updateStatus/{id}/{status}")
    public Result updateStatus(@PathVariable("id")Long id,
                                    @PathVariable("status")Integer status ){
        productService.updateStatus(id , status);
        return Result.ok();
    }

    @Operation(summary = "更新商品接口")
    @PutMapping("updateById")
    public Result updateById(@RequestBody ProductSaveDto productSaveDto){
        productService.updateById(productSaveDto);
        return Result.ok();
    }
    @Operation(summary = "根据spuid查询商品详情回显")
    @GetMapping("getById/{id}")
    public Result getById(@PathVariable("id")Long id){
        ProductSaveDto productSaveDto = productService.getById(id);
        return Result.ok(productSaveDto);
    }
    @Operation(summary = "新增商品接口")
    @PostMapping("save")
    public Result bigSave(@RequestBody ProductSaveDto productSaveDto){
        productService.bigSave(productSaveDto);
        return Result.ok();
    }


    //   /admin/product/product/1/10?brandId=1&category1Id=1&category2Id=2&category3Id=
    @Operation(summary = "条件查询spu分页数据")
    @GetMapping("{pageNum}/{pageSize}")
    public Result list(ProductDto productDto,
                       @PathVariable("pageNum")Integer pageNum,
                       @PathVariable("pageSize")Integer pageSize){
        PageInfo<ProductVo> pageInfo =  productService.list(productDto,pageNum,pageSize);
        return Result.ok(pageInfo);
    }
}
